/**
 * 
 * @desc    将以base64的图片URL的转换为Blob
 * @param   {String} urlData
 * @param   {String} blobType 默认 图片格式 'image/png'
 * @return  {Blob} 
 */
function base64UrlToBlob(urlData, blobType = 'image/png') {
  // 去掉头，并转换为byte
  const bytes = urlData && window.atob(urlData.split(',')[1]);

  // 处理异常,将ascii码小于0的转换为大于0
  const ab = new ArrayBuffer(bytes.length);
  const ia = new Uint8Array(ab);
  for (let i = 0; i < bytes.length; i++) {
    ia[i] = bytes.charCodeAt(i);
  }
  return new Blob([ab], { type: blobType });
}

export { base64UrlToBlob };